package com.znjc.web.controller.device;

import com.znjc.common.core.controller.BaseController;
import com.znjc.common.core.domain.AjaxResult;
import com.znjc.common.core.page.TableDataInfo;
import com.znjc.device.domain.DeviceData;
import com.znjc.device.domain.vo.TdengineQueryVO;
import com.znjc.device.service.DeviceDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/device/data")
@RestController
public class DeviceDataController extends BaseController {

    @Autowired
    private DeviceDataService deviceDataService;

    /**
     * Pagination Query
     *
     * @return
     */
    @GetMapping("/list")
    public TableDataInfo queryWeather(TdengineQueryVO queryVO) {
        startPage();
        return getDataTable(deviceDataService.getListIotData(queryVO));
    }

    /**
     * upload single weather info
     *
     * @param deviceData
     * @return
     */
    @PostMapping("/save")
    public AjaxResult saveDeviceData(@RequestBody DeviceData deviceData) {

        return toAjax(deviceDataService.save(deviceData));
    }

    /**
     * upload multi weather info
     *
     * @param dataList
     * @return
     */
    @PostMapping("/batch")
    public AjaxResult batchSaveWeather(@RequestBody List<DeviceData> dataList) {

        return toAjax(deviceDataService.saveBatch(dataList));
    }

}
